<template>
  <div>
    <p>用户名：<input type="text" v-model="name">
      <button @click="add">确认</button>
    </p>


  </div>
</template>

<script>
export default {
  name: "bindmobile",
  data() {
    return {
      type: this.$route.query.type,
      userid: this.$route.query.id,
      username: this.$route.query.username,
      uid: this.$route.query.uid,
      token: this.$route.query.token,
      name: ''
    }
  },
  methods: {
    add() {
      this.$axios.post('/users/bindmobile', {'name': this.name, 'uid': this.uid, 'token': this.token})
        .then(res => {
          if (res.data.code == 200) {
            localStorage.setItem('userid', res.data.userid)
            localStorage.setItem('username', res.data.username)
            this.$router.push('/')
          } else {
            alert(res.data.mes)
          }


        })

    }

  },
  mounted() {
    if (this.type == 1) {
      localStorage.setItem('userid', this.userid)
      localStorage.setItem('username', this.username)
      this.$router.push('/')
    } else {
      localStorage.setItem('uid', this.uid)
      localStorage.setItem('token', this.token)

    }

  }
}
</script>

<style scoped>

</style>
